#include <stdlib.h>

#include "conf_helper.h"

int main()
{
    char *pcFileName = "t_conf_helper.conf";

    CONFIG_CACHE_T *pstConfigCache = (CONFIG_CACHE_T *)malloc(sizeof(CONFIG_CACHE_T));

    if( OK != initConfigCache(pcFileName, pstConfigCache))
    {
        fprintf(stderr, "配置文件读取失败!\n");
        if (pstConfigCache != NULL)
        {
            free(pstConfigCache);
            pstConfigCache = NULL;
        }
        exit(-1);
    }

#if 0
    updateConfigCache(pstConfigCache);
#endif

    debugConfigCache(pstConfigCache);
    
    debugConfigCache(pstConfigCache);

    debugConfigCache(pstConfigCache);

    char *pcKey = "RFC";
    char **values = findInConfigCacheByKey(pstConfigCache, pcKey);


    if (values != NULL)
    {
        int i = 0;
        while(values[i] != NULL)
        {
            printf("%s=%s\n", pcKey, values[i++]);
        }
    }
    else
    {
        printf("%s has no value\n", pcKey);
    }
    /* 释放查询结果所占用的内存 */
    while (values != NULL)
    {
        while( *values != NULL)
        {
            free(*values);
            *values = NULL;
        }
        free(values);
        values = NULL;
    }

    destroyConfigCache(pstConfigCache);
    return 0;
}
